package com.qf.flash.ui.home.adapter;

import android.app.Activity;
import android.support.v7.widget.CardView;
import android.widget.ImageView;

import com.qf.flash.R;
import com.qf.flash.constant.FlashCodes;
import com.qf.flash.http.response.PlayTypeBean;
import com.qf.flash.ui.home.ScriptRoomActivity;
import com.qf.flash.ui.home.WolfKillActivity;
import com.qf.flash.utils.ImageLoader;
import com.qf.flashlib.adapter.BaseRViewItem;
import com.qf.flashlib.adapter.RViewHolder;

import org.greenrobot.eventbus.EventBus;

/**
 * 2020/3/11 17:20
 */
public class PlayTypeItem extends BaseRViewItem<PlayTypeBean> {

    private Activity activity;

    public PlayTypeItem() {
    }

    public PlayTypeItem(Activity activity) {
        this.activity = activity;
    }

    @Override
    public int getItemLayout() {
        return R.layout.item_play_type;
    }

    @Override
    public void convert(RViewHolder holder, PlayTypeBean entity, int position, int itemSize) {
        ImageView iv = holder.getView(R.id.iv_img);
        CardView cardView = holder.getView(R.id.cv_container);
        ImageLoader.load(iv.getContext(), entity.getImage(), iv);
        holder.setText(R.id.tv_name, entity.getName());
        cardView.setOnClickListener(v -> {
            if (activity == null) {
                EventBus.getDefault().post(entity);
            } else {
                switch (entity.getId()) {
                    case FlashCodes.PLAY_ROOM:// 密室
                    case FlashCodes.PLAY_SCRIPT://剧本
                        ScriptRoomActivity.start(activity, entity);
                        break;
                    default:// 狼人
                        WolfKillActivity.start(activity, entity);
                        break;
                }
            }

        });
    }
}
